<?php
/**
 * Created by PhpStorm.
 * User: xiaomeng
 * Date: 17-8-31
 * Time: 下午12:05
 */
namespace swf\core;

use swf\socket\Response;

class Controller
{
    public $server;
    public $frame;
    public $socketData;
    public $reqData;
    public $reqCmd;


    /**
     *
     * @param $server
     * @param $frame
     * @param $socketData
     */
    public function init($server,$frame,$data)
    {
        $this->server = $server;
        $this->frame = $frame;
        $this->socketData = $data;
        $this->reqData = $data['data'];
        $this->reqCmd = $data['cmd'];
    }

    //$server,$fd, $cmd, $data = [], $code = 0, $msg = 'ok'

    /**
     * 响应
     * @param $cmd
     * @param $data
     * @param int $code
     * @param string $msg
     */
    public function send($cmd,$data,$code = 0)
    {
        return Response::send($this->server,$this->frame->fd,$cmd,$data,$code);
    }


    /**
     * 群发
     * @param $cmd
     * @param $data
     * @param int $code
     * @param string $msg
     */
    public function sendAll($cmd,$fds,$data,$code = 0)
    {
        foreach ($fds as $fd)
        {
            Response::send($this->server,$fd,$cmd,$data,$code);
        }
        return true;
    }




}